package ClassStudy;

import sun.misc.Launcher;

import java.lang.reflect.Method;
import java.net.URL;

/**
 * @author Cheng Jun Description: 请输入描述
 * @version 1.0
 * @date 2021/8/18 19:55
 */
public class ClassLoaderTest {

  public static void main(String[] args) throws Exception {
    try {
      // 仅仅加载了类 调用ClassLoader.loadClass(String name)
      ClassLoader.getSystemClassLoader().loadClass("ClassStudy.ClassLoaderStudy");
      // 会 初始化类
      Class<?> aClass = Class.forName("ClassStudy.ClassLoaderStudy");
      Class<?> aClass1 = Class.forName("ClassStudy.ClassLoaderStudy");
      // 在堆内存中 每个类 只有一份 Class类对象
      System.out.println(aClass.equals(aClass1));

    } catch (ClassNotFoundException e) {
      e.printStackTrace();
      throw new ClassNotFoundException();
    }
    ClassLoaderStudy classLoaderStudy = new ClassLoaderStudy();
    System.out.println("dddd");
    String name = "Cauchy";
    Class<? extends String> aClass = name.getClass();
    ClassLoaderStudy classLoaderStudy1 = new ClassLoaderStudy();

    URL[] urLs = Launcher.getBootstrapClassPath().getURLs();

    for (URL urL : urLs) {
      System.out.println(urL);
    }

    for (Method method : Object.class.getMethods()) {
      // 反射能取到一切，native 也不例外
      System.out.println(method.getName());
    }
  }
}
